<template>
  <my-div class="exchange">
     <head></head>
      <my-div class="transfer-choose">
        <my-text text="个人中心" day_color="rgba(70,120,245,1)" night_color="rgba(184,111,36,1)"  class="transfer-title"></my-text>
        <div class="choose-currency">
          <text class="currency-name">头像</text>
          <div class="currency-wrapper" @click="openPhoto">
            <image style="width:80px;height:80px;" :src="avatar"></image>
            <image style="width:18px;height:32px;margin-left:24px;" src="root:img/home/right@2x.png"></image>
          </div>
        </div>
        <div class="choose-currency">
          <text class="currency-name">昵称</text>
          <div class="currency-wrapper" @click="$refs.sure_pw.show = true">
             <text class="currency-value">{{nickname}}</text>
            <image style="width:18px;height:32px;margin-left:24px;" src="root:img/home/right@2x.png"></image>
          </div>
        </div>
         <div class="choose-currency">
          <text class="currency-name" >用户名</text>
          <div class="currency-wrapper">
             <text class="currency-value">{{current_user.name}}</text>
          </div>
        </div>
         <div class="choose-currency">
          <text class="currency-name">钱包地址</text>
        </div>
          <div>
             <text class="currency-value">{{current_wallet.account_id}}</text>
            <!-- <image style="width:18px;height:32px;margin-left:12px;" src="root:img/home/right@2x.png"></image> -->
          </div>
        <!-- <div class="choose-currency" @click="push('root:pages/my/help_center.js')">
            <text class="currency-name">{{$t('my.help_center')}}</text>
            <div class="currency-wrapper">
              <image style="width:18px;height:32px;margin-left:24px;" src="root:img/home/right@2x.png"></image>
            </div>
          </div> -->
      </my-div>
      <alert-input ref='sure_pw' title="修改昵称" placeholder="请输入昵称" @success="sure_success"></alert-input>
  </my-div>
</template>

<script>
import { WxcButton } from 'weex-ui'
import AlertInput from '../../component/alert_input.vue';
export default {
  name: '',
  data() {
    return {
      avatar:'',
      nickname:''
    }
  },
  components: {WxcButton,AlertInput},
  computed: {},

  created() {
  },
  methods: {
    onLoad(){
      this.nickname = this.current_user.nickname || '点击设置'
      this.avatar = this.current_user.avatar || 'root:img/avatar@2x.png'
    },
    openPhoto(){
      const self = this
      const photo = weex.requireModule('photo');
       photo.open(400,400,'#000000','#ffffff','#ffffff',function(e){
        self.src=e.path;
        var param={};
        var path={};
        path.file=e.path;
        self.$http.uploadFile('index/avatarUpload',param,path,(res)=>{
          const data = JSON.parse(res)
          self.update_avatar(data.fileName,e.path)
        })
        });
    },
    // 更新用户昵称
    sure_success(val){
      this.$http.post('wallet/updateUserInfos',{account_id:this.current_wallet.account_id,nice_name:val},(res)=>{
        this.toast('设置成功')
        this.nickname = val
        this.current_user.nickname = val
        const notify = weex.requireModule('notify');
        notify.send('update_name', {nickname:this.nickname})
        notify.send('update_name1', {nickname:this.nickname})
        this.set_current_user(this.current_user)
      })
    },
    // 更新用户头像
    update_avatar(filename,filepath){
       this.$http.post('wallet/updateUserInfos',{account_id:this.current_wallet.account_id,avatar:filename},(res)=>{
        this.toast('设置成功')
        this.avatar = filepath
        this.current_user.avatar = filepath
        const notify = weex.requireModule('notify');
        notify.send('update_avatar',{avatar:filepath})
        notify.send('update_avatar1',{avatar:filepath})
        this.set_current_user(this.current_user)
      })

    }
  }
}
</script>
<style scoped>
.el-dialog .el-dialog__body {
  height: 600px;
}
.wrapper{
  display: flex;
  flex-direction: row;
}
.exchange{
  flex: 1;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
}
.sure-btn{
  position: absolute;
  bottom: 30px;
  left: 30px;
}
.transfer-choose{
  width: 720px;
  padding-left: 30px;
}
.transfer-title{
  margin-top: 24px;
  font-size: 48px;
  font-family: PingFang SC;

  margin-bottom: 104px;
}
.choose-currency{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 690px;
  height: 100px;
}
.currency-value{
  font-size: 28px;
  lines:1;
  color: rgba(70,120,245,1);
}
.currency-name{
  font-size: 30px;
  color: rgba(60,71,98,1);
}
.currency-wrapper{
  display: flex;
  flex-direction: row;
  height: 100px;
  align-items: center;
}
</style>